package com.example.cognitivesystemserver.controller;

import com.example.cognitivesystemserver.Exceptions.ParamsException;
import com.example.cognitivesystemserver.base.ResultInfo;
import com.example.cognitivesystemserver.base.ResultType;
import com.example.cognitivesystemserver.pojo.Evaluation;
import com.example.cognitivesystemserver.service.EvaluationService;
import com.example.cognitivesystemserver.service.EvaluationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class EvaluationController {

    @Resource
    private EvaluationService evaluationService;

    //返回具体某个学生测评结果。。。。。
    @GetMapping("/Eval/ShowRes")
    @ResponseBody
    public ResultType getEvaluationRes(String StuId){
        System.out.println("StuId:"+StuId);
        Evaluation evaluation=evaluationService.getEvaluationRes(StuId);
        Map<String,Double> map=new HashMap<>();
        map.put("Efficiency",9.88);
        map.put("AvgScore",90.7);
        map.put("Speed",3.88);
        ResultType resultType=new ResultType(200,"查询成功",map);
        return resultType;
    }


    //保存评估结果
    @PostMapping("/Eval/saveRes")
    @ResponseBody
    public ResultInfo saveEvalRes(Evaluation evaluation) {

        ResultInfo resultInfo=new ResultInfo();
        try {

            evaluationService.saveEvalRes(evaluation);
            resultInfo.setMsg("保存成功！");

        }catch (ParamsException p){
            resultInfo.setCode(p.getCode());
            resultInfo.setMsg(p.getMsg());
            p.printStackTrace();
        }catch (Exception e){
            resultInfo.setCode(500);
            resultInfo.setMsg("保存失败！");
            e.printStackTrace();
        }

        return resultInfo;
    }

    //查看全部学生测评结果
    @GetMapping("/Eval/getAllEval")
    public Object getAllEval() {
        List<Evaluation> evaluationList=evaluationService.getAllEval();
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("evaluationList",evaluationList);
        modelAndView.setViewName("evaluationList");
        return evaluationList;
    }


}
